#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e6 + 5;

int n;
string s;

void f(int l, int r, char& c, int& ans) {  // [l, r)
  if (r - l <= 1) {
    c = s[l];
    ans = 1;
    return;
  }
  int m1 = l + (r - l) / 3;
  int m2 = r - (r - l) / 3;
  char res[3];
  int cnt[3];
  f(l, m1, res[0], cnt[0]);
  f(m1, m2, res[1], cnt[1]);
  f(m2, r, res[2], cnt[2]);
  if (res[0] == res[1] || res[0] == res[2])
    c = res[0];
  else
    c = res[1];
  int sum = 0, mx = 0;
  rep(i, 0, 2) if (res[i] == c) sum += cnt[i], mx = max(mx, cnt[i]);
  ans = sum - mx;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> s;
  n = s.size();
  char c;
  int ans;
  f(0, n, c, ans);
  cout << ans;
  return 0;
}